package controller;

import org.junit.Test;
import pojo.Bed;
import service.BedService;
import service.BedServiceImpl;

import java.sql.Connection;
import java.util.ArrayList;


public class BedController {
    private BedService service = new BedServiceImpl();

    /*
        查询所有床铺信息
     */
    @Test
    public void findAll() {
        ArrayList<Bed> list = service.findAll();
        for(Bed bed : list) {
            System.out.println(bed);
        }
    }

    /*
        条件查询，根据id查询床铺信息
     */
    @Test
    public void findByBedId() {
        Bed bed = service.findById(101, 1);
        System.out.println(bed);
    }

    @Test
    public void findByBedReturnBool(){
        System.out.println(service.findByIdReturnBool(101, 1));
    }

    /*
        添加床铺信息
     */
    @Test
    public void insert() {
        Bed bed = new Bed(203,1,true);
        int result = service.insert(bed);

        if(result!=0) {
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改床铺信息
     */
    @Test
    public void update() {

        Bed bed = service.findById(203,1);
        int result = service.update(bed);

        if(result != 0) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    /*
        删除床铺信息
     */
    @Test
    public void delete() {
        int result = service.delete(service.findById(203, 1));
        if(result == 2 ) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
